package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysColour;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class SaveColorAction extends AbstractBaseAction {
	private static final long serialVersionUID = 3445217901561452700L;
	private String colorName;

	public void setColorName(String colorName) {
		this.colorName = colorName;
	}

	@Override
	public String execute() {
		try {
			if(StringUtil.isEmpty(colorName)){
				statusCode = "300";
				message = "请输入颜色名称!!";
			}else{
				SysProductBusinessService spbs = new SysProductBusinessService();
				SysColour color = new SysColour();
				color.setColourName(colorName);
				color.setDealFlag(ConstantTool.DEAL_FALG_OK);
				color.setStatus(ConstantTool.STATUS_OK);
				List<SysColour> colorList = spbs.getSysColorExample(color);
				if(null != colorList && colorList.size() >0){
					statusCode = "300";
					message = "输入的颜色已经存在, 无需新增!";
				}else{
					String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
					SysUser user = (SysUser) getSession().getAttribute("SysUser");
					String userId = user.getId()+"";
					color.setInsertTime(strTime);
					color.setInsertUserId(userId);
					color.setModifyTime(strTime);
					color.setUpdateUserId(userId);
					String exeStatus = spbs.saveSysColor(color);
					if("SUCCESS".equals(exeStatus)){
						statusCode = "200";
						message = "保存颜色信息成功!";
					}else{
						statusCode = "300";
						message = "系统繁忙, 保存颜色信息失败!";
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常,保存颜色信息失败!";
		}
		return SUCCESS;
	}
}
